/*
 * NativeTestCase.h  0.4.0 / Nov 5, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef NATIVETESTCASE_H
#define NATIVETESTCASE_H

#ifdef CUTE4J_TEST

#include "Cute4jCore.h"

// NativeTestCase :: Protected Member Functions. -------------------------------

/*!
 * \brief Native Test Case.
 *
 * \author Slobodan Vrkacevic (slobodan.vrkacevic@gmail.com)
 * \version 0.2.0
 */
class CUTE4J_EXPORT NativeTestCase : public QObject
{
  Q_OBJECT
public:
  NativeTestCase(JNIEnv *env, jobject obj);
  virtual ~NativeTestCase();
public:
  static void initialize(JNIEnv *env, jclass cls);
  static jlong testObject(JNIEnv *env, jobject obj);
protected:
  void failCondition(const char *condition = 0, const char *fileName = 0,
                     int lineNumber = -1);
protected:
  inline JNIEnv *env() const;
  inline jweak obj() const;
private:
  JNIEnv *m_env;
  jweak m_obj;
private:
  static jfieldID sm_testObjectFID;
  static jmethodID sm_failConditionMID;
};

// NativeTestCase :: Public Inline Member Functions. ---------------------------

/*!
 * \brief Returns JNIEnv pointer.
 *
 * \return JNIEnv pointer
 */
inline JNIEnv *NativeTestCase::env() const
{
  return m_env;
}

/*!
 * \brief Returns weak reference.
 *
 * \return weak reference
 */
inline jweak NativeTestCase::obj() const
{
  return m_obj;
}

// Macro Definitions. ----------------------------------------------------------

#define nativeTestCase (reinterpret_cast<NativeTestCase *>(testObject))

#endif // CUTE4J_TEST

#endif // NATIVETESTCASE_H
